package org.bemo.utils;

import java.io.FileReader;

import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

public class JsUtil {
	
	public static String invk(String s1){
		 String execute = null;
		ScriptEngineManager manager = new ScriptEngineManager();
	       ScriptEngine engine = manager.getEngineByName("js");
	       try {
	         String path = JsUtil.class.getResource("").getPath();
	         //System.out.println(path);
	         // FileReader的参数为所要执行的js文件的路径
	         engine.eval(new FileReader(path + "demo.js"));
	         if (engine instanceof Invocable) {
	           Invocable invocable = (Invocable) engine;
	           Methods executeMethod = invocable.getInterface(Methods.class);
	           execute = executeMethod.execute(s1);
	         }
	       } catch (Exception e) {
	         e.printStackTrace();
	       }
		return execute;
	}

}
